package mani.threads;

import java.util.Date;
import java.util.concurrent.TimeUnit;

public class ThreadLocalVariable implements Runnable {
	private static ThreadLocal<Date> startDate = new ThreadLocal<Date>(){
		protected Date initialValue(){
			return new Date();
			}
	};
	
	public void run(){
		System.out.printf("Starting thread is: %s :%s\n", Thread.currentThread().getId(), startDate.get());
		try {
			TimeUnit.SECONDS.sleep((int)Math.rint(Math.random()*10));
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.printf("Finished thread is: %s :%s\n", Thread.currentThread().getId(), startDate.get());
	}
}
